let shadows = document.getElementsByClassName("shadow")
let cancel = document.getElementById("cancel-button")
cancel.style.display = "none"


for (shadow of shadows){
    shadow.style.display = "none"
}

// let teacher_has_logined = document.getElementById("application-scope").innerHTML
// if(teacher_has_logined == "1"){
//
//     $.ajax({
//         type: "GET",
//         url: "history",
//         dataType: "json",
//         success: function(data){
//             if(data.hasOwnProperty("code")){
//                 console.log("success")
//             }
//         }
//     });
// }else{
//     window.location.href = "login-teacher.jsp"
// }



$('#delete-button').click(function(){
    cancel.style.display = "block"
    for (shadow of shadows){
        shadow.style.display = "block"
    }
})





$('#cancel-button').click(function(){
    cancel.style.display = "none"
    for (shadow of shadows){
        shadow.style.display = "none"
    }
})

var btns = document.getElementsByClassName("delete-btn");
//利用let定义i
for(let i = 0; i < btns.length; i++) {
    var btn = btns[i];
    btn.onclick = function () {
        let id = document.getElementsByClassName("delete-flag")[i].innerHTML
        console.log("请求删除的id：" + id)
        $.ajax({
            type: "GET",
            url: "delete",
            data:{id:id},
            dataType: "json",
            success: function(data){
                if(data.msg == "ok"){
                    console.log("删除成功")
                    let deleteItem = document.getElementsByClassName("history-view")[i]
                    deleteItem.innerHTML = "删除成功"
                    deleteItem.style.color = "#407ab1"
                    deleteItem.style.textAlign = "center"
                    deleteItem.style.lineHeight = "60px"
                    deleteItem.style.height = "80px"
                    deleteItem.style.fontSize = "14px"
                    setTimeout(function(){
                        let parent = document.getElementById("parent");
                        parent.removeChild(deleteItem)
                        $("#flush-btn").trigger("click");
                    },1600);



                }else{
                    console.log("删除失败")
                }
            }
        });



    };
}